﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class Multi_flute_grooving_and_cut_off_inserts
    {
        public static void Multiflutegroovingandcutoffinserts(Dictionary<string, Object> data)  //多刃切槽和切断刀片
        {
            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour");//轮廓层
            Layer dimensioning = new Layer("dimensioning");//尺寸层
            Layer refin = new Layer("refin");//基准线/内轮廓/虚线
            Layer center = new Layer("center");//中心线
            Layer textlayer = new Layer("textlayer");//文本层
            Layer hatching = new Layer("hatching");//填充层
            Layer additionalline = new Layer("additionalline");//附加线
            Layer cutting = new Layer("cutting");//切削层
            fun.SetLayer(dxf);

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            /*double CW = 7.03;
            double PDX = 13.07;
            double WF = 61.12;
            double LF = 13.05;
            double OAL = 19.11;
            double OAW = 122.23;
            double PDPT = 17.38;
            double AN = 20;
            double GAMP = 20;
            double scale = 122.23 / OAW; //放大系数*/
            double scale = Convert.ToDouble(data["scale"]); //放大系数

            double offset = 10;

            double CW = Convert.ToDouble(data["cw"])*scale;
            double PDX = Convert.ToDouble(data["pdx"]) * scale;
            double WF = Convert.ToDouble(data["wf"]) * scale;
            double LF = Convert.ToDouble(data["lf"]) * scale;
            double OAL = Convert.ToDouble(data["oal"]) * scale;
            double OAW = Convert.ToDouble(data["oaw"]) * scale;
            double PDPT = Convert.ToDouble(data["pdpt"]) * scale;
            double AN = Convert.ToDouble(data["an"]);
            double GAMP = Convert.ToDouble(data["gamp"]);

            //非参数化参数----------------------------------------------------------
            double long1 = 30.48 * scale;//五边形
            double jd = 95;

            double r = 19.11 * scale;//内圆 

            double long2 = 43.93 * scale;//多边形
            double jd2 = 119;

            //切削部分
            double jd3 = 150;
            double jd4 = 78;
            double long3 = 9.91 * scale;
            double long4 = 10.85 * scale;
            double long5 = 3.79 * scale;


            //点---------------------------------------------------------------------------------------------
            //第一部分
            //中心线点(1-4)
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + OAL +2, v1.Y);
            Vector2 v3 = new Vector2(v1.X + fun.CalDistance(v1, v2) / 2.0, v1.Y + OAW/2 +2);
            Vector2 v4 = new Vector2(v1.X + fun.CalDistance(v1, v2) / 2.0, v1.Y - OAW/2 -2);

            //轮廓点
            Vector2 v5 = new Vector2(v1.X + (fun.CalDistance(v1, v2) - OAL) / 2.0, v1.Y);
            Vector2 v6 = new Vector2(v5.X, v5.Y + WF * 0.4);
            Vector2 v7 = new Vector2(v6.X + (OAL - LF) * 0.6, v6.Y);
            Vector2 v8 = new Vector2(v7.X, v1.Y + WF * 0.6);
            Vector2 v9 = new Vector2(v6.X + (PDX - CW), v8.Y);
            Vector2 v10 = new Vector2(v9.X, v1.Y + WF);
            Vector2 v11 = new Vector2(v10.X + CW, v10.Y);
            Vector2 v12 = fun.mirrorpoint(v9, v3, v4);
            Vector2 v13 = fun.mirrorpoint(v8, v3, v4);
            Vector2 v14 = fun.mirrorpoint(v7, v3, v4);
            Vector2 v15 = fun.mirrorpoint(v6, v3, v4);
            Vector2 v16 = fun.mirrorpoint(v5, v3, v4);
            Vector2 v17 = fun.mirrorpoint(v15, v1, v2);
            Vector2 v18 = fun.mirrorpoint(v14, v1, v2);
            Vector2 v19 = new Vector2(v18.X, v18.Y - WF / 3.0);
            Vector2 v20 = new Vector2(v12.X, v19.Y);
            Vector2 v21 = fun.mirrorpoint(v11, v1, v2);
            Vector2 v22 = fun.mirrorpoint(v21, v3, v4);
            Vector2 v23 = fun.mirrorpoint(v20, v3, v4);
            Vector2 v24 = fun.mirrorpoint(v19, v3, v4);
            Vector2 v25 = fun.mirrorpoint(v18, v3, v4);
            Vector2 v26 = fun.mirrorpoint(v17, v3, v4);

            //内部点
            Vector2 v27 = new Vector2(v7.X, v5.Y);
            Vector2 v28 = new Vector2(v7.X, v7.Y + fun.CalDistance(v7, v8) / 2);
            Vector2 v29 = new Vector2(v9.X, v9.Y + fun.CalDistance(v9, v10) * 0.8);
            Vector2 v30 = fun.mirrorpoint(v29, v3, v4);
            Vector2 v31 = fun.mirrorpoint(v28, v3, v4);
            Vector2 v32 = new Vector2(v9.X, v28.Y);
            Vector2 v33 = fun.mirrorpoint(v32, v3, v4);
            Vector2 v34 = fun.mirrorpoint(v27, v3, v4);
            Vector2 v35 = new Vector2(v5.X + (OAL - LF), v5.Y);
            Vector2 v36 = new Vector2(v35.X, v35.Y + (v28.Y - v27.Y) * 0.6);
            Vector2 v37 = fun.mirrorpoint(v36, v3, v4);
            Vector2 v38 = fun.mirrorpoint(v35, v3, v4);
            Vector2 v39 = new Vector2(v35.X, v35.Y + (v36.Y - v35.Y) * 0.5);
            Vector2 v40 = fun.mirrorpoint(v39, v3, v4);
            Vector2 v41 = new Vector2(v5.X, v5.Y + (v6.Y - v5.Y) * 0.7);
            Vector2 v42 = new Vector2(v27.X, v41.Y);
            Vector2 v43 = new Vector2(v27.X, v39.Y + (v36.Y - v39.Y) * 0.8);
            Vector2 v44 = new Vector2(v39.X, v39.Y + (v36.Y - v39.Y) * 0.8);
            Vector2 v45 = fun.mirrorpoint(v41, v3, v4);
            Vector2 v46 = fun.mirrorpoint(v42, v3, v4);
            Vector2 v47 = fun.mirrorpoint(v43, v3, v4);
            Vector2 v48 = fun.mirrorpoint(v44, v3, v4);
            Vector2 v49 = new Vector2(v27.X, v27.Y - (v27.Y - v25.Y) * 0.5);
            Vector2 v50 = fun.mirrorpoint(v49, v3, v4);
            Vector2 v51 = new Vector2(v18.X, v18.Y - (v18.Y - v19.Y) * 0.2);
            Vector2 v52 = fun.mirrorpoint(v51, v3, v4);
            Vector2 v53 = new Vector2(v40.X, v50.Y);
            Vector2 v54 = fun.mirrorpoint(v53, v3, v4);
            Vector2 v55 = new Vector2(v25.X, v25.Y + (v27.Y - v25.Y) * 0.4);
            Vector2 v56 = new Vector2(v26.X, v55.Y);
            Vector2 v57 = fun.mirrorpoint(v55, v3, v4);
            Vector2 v58 = fun.mirrorpoint(v56, v3, v4);
            Vector2 v59 = new Vector2(v20.X, v51.Y);
            Vector2 v60 = fun.mirrorpoint(v59, v3, v4);
            Vector2 v61 = new Vector2(v23.X, v23.Y + (v25.Y - v24.Y) * 0.4);
            Vector2 v62 = new Vector2(v24.X, v61.Y);
            Vector2 v63 = fun.mirrorpoint(v61, v3, v4);
            Vector2 v64 = fun.mirrorpoint(v62, v3, v4);
            Vector2 v65 = new Vector2(v23.X, v61.Y - (v25.Y - v24.Y) * 0.1);
            Vector2 v66 = fun.mirrorpoint(v65, v3, v4);
            Vector2 v67 = new Vector2(v23.X, v23.Y + (v25.Y - v24.Y) * 0.1);
            Vector2 v68 = fun.mirrorpoint(v67, v3, v4);

            //第二部分点
            //中心线点
            Vector2 v69_1 = new Vector2(v2.X + OAW * 1.2, v2.Y);
            Vector2 v69 = new Vector2(v69_1.X - WF / 3.0 * 1.1, v69_1.Y);
            Vector2 v70 = new Vector2(v69_1.X + WF / 3.0 * 1.1, v69_1.Y);
            Vector2 v71 = new Vector2(v69_1.X, v69_1.Y + WF / 3.0 * 1.1);
            Vector2 v72 = new Vector2(v69_1.X, v69_1.Y - WF / 3.0 * 1.1);

            //五边形点
            Vector2 v73 = fun.Polar(v69_1, jd * pi / 180, long1);
            Vector2 v74 = fun.rotatePoint_Changed(v69_1, v73, -72);
            Vector2 v75 = fun.rotatePoint_Changed(v69_1, v74, -72);
            Vector2 v76 = fun.rotatePoint_Changed(v69_1, v75, -72);
            Vector2 v77 = fun.rotatePoint_Changed(v69_1, v76, -72);

            //大五边形点
            Vector2 v78 = fun.Polar(v69_1, jd2 * pi / 180, long2);
            Vector2 v79 = fun.rotatePoint_Changed(v69_1, v78, -36);
            Vector2 v80 = fun.rotatePoint_Changed(v69_1, v79, -36);
            Vector2 v81 = fun.rotatePoint_Changed(v69_1, v80, -36);
            Vector2 v82 = fun.rotatePoint_Changed(v69_1, v81, -36);
            Vector2 v83 = fun.rotatePoint_Changed(v69_1, v82, -36);
            Vector2 v84 = fun.rotatePoint_Changed(v69_1, v83, -36);
            Vector2 v85 = fun.rotatePoint_Changed(v69_1, v84, -36);
            Vector2 v86 = fun.rotatePoint_Changed(v69_1, v85, -36);
            Vector2 v77_1 = fun.rotatePoint_Changed(v69_1, v86, -36);//图上77处

            //切削部分点
            Vector2 v87 = fun.Polar(v69_1, jd3 * pi / 180, OAW / 2.0);
            Vector2 v88 = fun.Polar(v87, (60 - AN) * pi / 180, long3);
            Vector2 v89 = fun.Polar(v87, -(180 - jd3) * pi / 180, long4);
            Vector2 v90 = fun.Polar(v89, -jd4 * pi / 180, long5);

            Vector2 v91 = fun.rotatePoint_Changed(v69_1, v87, -72);
            Vector2 v92 = fun.rotatePoint_Changed(v69_1, v88, -72);
            Vector2 v93 = fun.rotatePoint_Changed(v69_1, v89, -72);
            Vector2 v94 = fun.rotatePoint_Changed(v69_1, v90, -72);

            Vector2 v95 = fun.rotatePoint_Changed(v69_1, v91, -72);
            Vector2 v96 = fun.rotatePoint_Changed(v69_1, v92, -72);
            Vector2 v97 = fun.rotatePoint_Changed(v69_1, v93, -72);
            Vector2 v98 = fun.rotatePoint_Changed(v69_1, v94, -72);

            Vector2 v99 = fun.rotatePoint_Changed(v69_1, v95, -72);
            Vector2 v100 = fun.rotatePoint_Changed(v69_1, v96, -72);
            Vector2 v101 = fun.rotatePoint_Changed(v69_1, v97, -72);
            Vector2 v102 = fun.rotatePoint_Changed(v69_1, v98, -72);

            Vector2 v103 = fun.rotatePoint_Changed(v69_1, v99, -72);
            Vector2 v104 = fun.rotatePoint_Changed(v69_1, v100, -72);
            Vector2 v105 = fun.rotatePoint_Changed(v69_1, v101, -72);
            Vector2 v106 = fun.rotatePoint_Changed(v69_1, v102, -72);

            //作图部分-----------------------------------------------------------------------
            //第一部分
            //中心线
            Line center_line1 = new Line(v1, v2);
            center_line1.Layer = center;
            center_line1.Linetype = Linetype.Center;
            center_line1.LinetypeScale = 5;
            dxf.AddEntity(center_line1);

            Line center_line2 = new Line(v3, v4);
            center_line2.Layer = center;
            center_line2.Linetype = Linetype.Center;
            center_line2.LinetypeScale = 5;
            dxf.AddEntity(center_line2);

            //轮廓
            LwPolyline polyline1 = new LwPolyline();
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));
            polyline1.Vertexes.Add(new LwPolylineVertex(v6));
            polyline1.Vertexes.Add(new LwPolylineVertex(v7));
            polyline1.Vertexes.Add(new LwPolylineVertex(v8));
            polyline1.Vertexes.Add(new LwPolylineVertex(v9));
            polyline1.Vertexes.Add(new LwPolylineVertex(v10));
            polyline1.Vertexes.Add(new LwPolylineVertex(v11));
            polyline1.Vertexes.Add(new LwPolylineVertex(v12));
            polyline1.Vertexes.Add(new LwPolylineVertex(v13));
            polyline1.Vertexes.Add(new LwPolylineVertex(v14));
            polyline1.Vertexes.Add(new LwPolylineVertex(v15));
            polyline1.Vertexes.Add(new LwPolylineVertex(v16));
            polyline1.Vertexes.Add(new LwPolylineVertex(v17));
            polyline1.Vertexes.Add(new LwPolylineVertex(v18));
            polyline1.Vertexes.Add(new LwPolylineVertex(v19));
            polyline1.Vertexes.Add(new LwPolylineVertex(v20));
            polyline1.Vertexes.Add(new LwPolylineVertex(v21));
            polyline1.Vertexes.Add(new LwPolylineVertex(v22));
            polyline1.Vertexes.Add(new LwPolylineVertex(v23));
            polyline1.Vertexes.Add(new LwPolylineVertex(v24));
            polyline1.Vertexes.Add(new LwPolylineVertex(v25));
            polyline1.Vertexes.Add(new LwPolylineVertex(v26));
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));
            fun.PolyFill(dxf, polyline1, 0.3, contour);

            //内部上半连线
            LwPolyline polyline2 = new LwPolyline();
            polyline2.Vertexes.Add(new LwPolylineVertex(v28));
            polyline2.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, polyline2, 0.3, contour);

            LwPolyline polyline3 = new LwPolyline();
            polyline3.Vertexes.Add(new LwPolylineVertex(v41));
            polyline3.Vertexes.Add(new LwPolylineVertex(v42));
            fun.PolyFill(dxf, polyline3, 0.3, contour);

            LwPolyline polyline4 = new LwPolyline();
            polyline4.Vertexes.Add(new LwPolylineVertex(v46));
            polyline4.Vertexes.Add(new LwPolylineVertex(v45));
            fun.PolyFill(dxf, polyline4, 0.3, contour);

            LwPolyline polyline5 = new LwPolyline();
            polyline5.Vertexes.Add(new LwPolylineVertex(v43));
            polyline5.Vertexes.Add(new LwPolylineVertex(v44));
            fun.PolyFill(dxf, polyline5, 0.3, contour);

            LwPolyline polyline6 = new LwPolyline();
            polyline6.Vertexes.Add(new LwPolylineVertex(v48));
            polyline6.Vertexes.Add(new LwPolylineVertex(v47));
            fun.PolyFill(dxf, polyline6, 0.3, contour);

            LwPolyline polyline7 = new LwPolyline();
            polyline7.Vertexes.Add(new LwPolylineVertex(v39));
            polyline7.Vertexes.Add(new LwPolylineVertex(v40));
            fun.PolyFill(dxf, polyline7, 0.3, contour);

            LwPolyline polyline8 = new LwPolyline();
            polyline8.Vertexes.Add(new LwPolylineVertex(v28));
            polyline8.Vertexes.Add(new LwPolylineVertex(v31));
            fun.PolyFill(dxf, polyline8, 0.3, contour);

            LwPolyline polyline9 = new LwPolyline();
            polyline9.Vertexes.Add(new LwPolylineVertex(v9));
            polyline9.Vertexes.Add(new LwPolylineVertex(v32));
            fun.PolyFill(dxf, polyline9, 0.3, contour);

            LwPolyline polyline10 = new LwPolyline();
            polyline10.Vertexes.Add(new LwPolylineVertex(v12));
            polyline10.Vertexes.Add(new LwPolylineVertex(v33));
            fun.PolyFill(dxf, polyline10, 0.3, contour);

            LwPolyline polyline11 = new LwPolyline();
            polyline11.Vertexes.Add(new LwPolylineVertex(v7));
            polyline11.Vertexes.Add(new LwPolylineVertex(v27));
            fun.PolyFill(dxf, polyline11, 0.3, contour);

            LwPolyline polyline12 = new LwPolyline();
            polyline12.Vertexes.Add(new LwPolylineVertex(v14));
            polyline12.Vertexes.Add(new LwPolylineVertex(v34));
            fun.PolyFill(dxf, polyline12, 0.3, contour);

            LwPolyline polyline13 = new LwPolyline();
            polyline13.Vertexes.Add(new LwPolylineVertex(v35));
            polyline13.Vertexes.Add(new LwPolylineVertex(v36));
            polyline13.Vertexes.Add(new LwPolylineVertex(v37));
            polyline13.Vertexes.Add(new LwPolylineVertex(v38));
            fun.PolyFill(dxf, polyline13, 0.3, contour);

            LwPolyline polyline14 = new LwPolyline();
            polyline14.Vertexes.Add(new LwPolylineVertex(v29));
            polyline14.Vertexes.Add(new LwPolylineVertex(v30));
            fun.PolyFill(dxf, polyline14, 0.3, contour);

            LwPolyline polyline15 = new LwPolyline();
            polyline15.Vertexes.Add(new LwPolylineVertex(v27));
            polyline15.Vertexes.Add(new LwPolylineVertex(v25));
            fun.PolyFill(dxf, polyline15, 0.3, contour);

            LwPolyline polyline16 = new LwPolyline();
            polyline16.Vertexes.Add(new LwPolylineVertex(v34));
            polyline16.Vertexes.Add(new LwPolylineVertex(v18));
            fun.PolyFill(dxf, polyline16, 0.3, contour);

            LwPolyline polyline17 = new LwPolyline();
            polyline17.Vertexes.Add(new LwPolylineVertex(v49));
            polyline17.Vertexes.Add(new LwPolylineVertex(v50));
            fun.PolyFill(dxf, polyline17, 0.3, contour);

            LwPolyline polyline18 = new LwPolyline();
            polyline18.Vertexes.Add(new LwPolylineVertex(v35));
            polyline18.Vertexes.Add(new LwPolylineVertex(v54));
            fun.PolyFill(dxf, polyline18, 0.3, contour);

            LwPolyline polyline19 = new LwPolyline();
            polyline19.Vertexes.Add(new LwPolylineVertex(v38));
            polyline19.Vertexes.Add(new LwPolylineVertex(v53));
            fun.PolyFill(dxf, polyline19, 0.3, contour);

            LwPolyline polyline20 = new LwPolyline();
            polyline20.Vertexes.Add(new LwPolylineVertex(v56));
            polyline20.Vertexes.Add(new LwPolylineVertex(v55));
            fun.PolyFill(dxf, polyline20, 0.3, contour);

            LwPolyline polyline21 = new LwPolyline();
            polyline21.Vertexes.Add(new LwPolylineVertex(v57));
            polyline21.Vertexes.Add(new LwPolylineVertex(v58));
            fun.PolyFill(dxf, polyline21, 0.3, contour);

            LwPolyline polyline22 = new LwPolyline();
            polyline22.Vertexes.Add(new LwPolylineVertex(v52));
            polyline22.Vertexes.Add(new LwPolylineVertex(v51));
            fun.PolyFill(dxf, polyline22, 0.3, contour);

            LwPolyline polyline23 = new LwPolyline();
            polyline23.Vertexes.Add(new LwPolylineVertex(v60));
            polyline23.Vertexes.Add(new LwPolylineVertex(v23));
            fun.PolyFill(dxf, polyline23, 0.3, contour);

            LwPolyline polyline24 = new LwPolyline();
            polyline24.Vertexes.Add(new LwPolylineVertex(v59));
            polyline24.Vertexes.Add(new LwPolylineVertex(v20));
            fun.PolyFill(dxf, polyline24, 0.3, contour);

            LwPolyline polyline25 = new LwPolyline();
            polyline25.Vertexes.Add(new LwPolylineVertex(v62));
            polyline25.Vertexes.Add(new LwPolylineVertex(v61));
            fun.PolyFill(dxf, polyline25, 0.3, contour);

            LwPolyline polyline26 = new LwPolyline();
            polyline26.Vertexes.Add(new LwPolylineVertex(v63));
            polyline26.Vertexes.Add(new LwPolylineVertex(v64));
            fun.PolyFill(dxf, polyline26, 0.3, contour);

            LwPolyline polyline27 = new LwPolyline();
            polyline27.Vertexes.Add(new LwPolylineVertex(v65));
            polyline27.Vertexes.Add(new LwPolylineVertex(v66));
            fun.PolyFill(dxf, polyline27, 0.3, contour);

            LwPolyline polyline28 = new LwPolyline();
            polyline28.Vertexes.Add(new LwPolylineVertex(v67));
            polyline28.Vertexes.Add(new LwPolylineVertex(v68));
            fun.PolyFill(dxf, polyline28, 0.3, contour);

            //第二部分
            Line center_line3 = new Line(v69, v70);
            center_line3.Layer = center;
            center_line3.Linetype = Linetype.Center;
            center_line3.LinetypeScale = 5;
            dxf.AddEntity(center_line3);

            Line center_line4 = new Line(v71, v72);
            center_line4.Layer = center;
            center_line4.Linetype = Linetype.Center;
            center_line4.LinetypeScale = 5;
            dxf.AddEntity(center_line4);

            fun.drawcircle(dxf, v69_1, r, 0.3, contour);//最内圆

            LwPolyline polyline29 = new LwPolyline();//五边形
            polyline29.Vertexes.Add(new LwPolylineVertex(v73));
            polyline29.Vertexes.Add(new LwPolylineVertex(v74));
            polyline29.Vertexes.Add(new LwPolylineVertex(v75));
            polyline29.Vertexes.Add(new LwPolylineVertex(v76));
            polyline29.Vertexes.Add(new LwPolylineVertex(v77));
            polyline29.Vertexes.Add(new LwPolylineVertex(v73));
            fun.PolyFill(dxf, polyline29, 0.3, contour);

            Circle circle1 = new Circle(v69_1, long1);
            circle1.Linetype = Linetype.Dashed;
            circle1.Layer = refin;
            circle1.LinetypeScale = 5;
            dxf.AddEntity(circle1);

            LwPolyline polyline30 = new LwPolyline();//多边形
            polyline30.Vertexes.Add(new LwPolylineVertex(v78));
            polyline30.Vertexes.Add(new LwPolylineVertex(v79));
            polyline30.Vertexes.Add(new LwPolylineVertex(v80));
            polyline30.Vertexes.Add(new LwPolylineVertex(v81));
            polyline30.Vertexes.Add(new LwPolylineVertex(v82));
            polyline30.Vertexes.Add(new LwPolylineVertex(v83));
            polyline30.Vertexes.Add(new LwPolylineVertex(v84));
            polyline30.Vertexes.Add(new LwPolylineVertex(v85));
            polyline30.Vertexes.Add(new LwPolylineVertex(v86));
            polyline30.Vertexes.Add(new LwPolylineVertex(v77_1));
            polyline30.Vertexes.Add(new LwPolylineVertex(v78));
            fun.PolyFill(dxf, polyline30, 0.3, contour);

            LwPolyline polyline31 = new LwPolyline();//切削部分
            polyline31.Vertexes.Add(new LwPolylineVertex(v77_1));
            polyline31.Vertexes.Add(new LwPolylineVertex(v90));
            polyline31.Vertexes.Add(new LwPolylineVertex(v89));
            polyline31.Vertexes.Add(new LwPolylineVertex(v87));
            polyline31.Vertexes.Add(new LwPolylineVertex(v88));
            polyline31.Vertexes.Add(new LwPolylineVertex(v78));
            fun.PolyFill(dxf, polyline31, 0.3, contour);

            LwPolyline polyline32 = new LwPolyline();//切削部分
            polyline32.Vertexes.Add(new LwPolylineVertex(v79));
            polyline32.Vertexes.Add(new LwPolylineVertex(v94));
            polyline32.Vertexes.Add(new LwPolylineVertex(v93));
            polyline32.Vertexes.Add(new LwPolylineVertex(v91));
            polyline32.Vertexes.Add(new LwPolylineVertex(v92));
            polyline32.Vertexes.Add(new LwPolylineVertex(v80));
            fun.PolyFill(dxf, polyline32, 0.3, contour);

            LwPolyline polyline33 = new LwPolyline();//切削部分
            polyline33.Vertexes.Add(new LwPolylineVertex(v81));
            polyline33.Vertexes.Add(new LwPolylineVertex(v98));
            polyline33.Vertexes.Add(new LwPolylineVertex(v97));
            polyline33.Vertexes.Add(new LwPolylineVertex(v95));
            polyline33.Vertexes.Add(new LwPolylineVertex(v96));
            polyline33.Vertexes.Add(new LwPolylineVertex(v82));
            fun.PolyFill(dxf, polyline33, 0.3, contour);

            LwPolyline polyline34 = new LwPolyline();//切削部分
            polyline34.Vertexes.Add(new LwPolylineVertex(v83));
            polyline34.Vertexes.Add(new LwPolylineVertex(v102));
            polyline34.Vertexes.Add(new LwPolylineVertex(v101));
            polyline34.Vertexes.Add(new LwPolylineVertex(v99));
            polyline34.Vertexes.Add(new LwPolylineVertex(v100));
            polyline34.Vertexes.Add(new LwPolylineVertex(v84));
            fun.PolyFill(dxf, polyline34, 0.3, contour);

            LwPolyline polyline35 = new LwPolyline();//切削部分
            polyline35.Vertexes.Add(new LwPolylineVertex(v85));
            polyline35.Vertexes.Add(new LwPolylineVertex(v106));
            polyline35.Vertexes.Add(new LwPolylineVertex(v105));
            polyline35.Vertexes.Add(new LwPolylineVertex(v103));
            polyline35.Vertexes.Add(new LwPolylineVertex(v104));
            polyline35.Vertexes.Add(new LwPolylineVertex(v86));
            fun.PolyFill(dxf, polyline35, 0.3, contour);

            Circle circle2 = new Circle(v69_1, OAW / 2.0);//最外虚线
            circle2.Linetype = Linetype.Dashed;
            circle2.Layer = refin;
            circle2.LinetypeScale = 5;
            dxf.AddEntity(circle2);

            //标注---------------------------------------------------------------------------
            double height = 3.5;
            double arrowsize = 3.5;
            double exline = 0.5 ;

            //PDX
            fun.dimrot1(dxf, v15, fun.Inters(v15, new Vector2(v15.X - OAW, v15.Y), v3, v4), 0, offset+OAW/2-v15.Y, 1, height, arrowsize, exline, "PDX" /*+ Math.Round(PDX, 2)*/, " ", " ");

            //CW
            fun.dimrot1(dxf, v11, v10, 0, offset*2, 0.5, height, arrowsize, exline, "CW" /*+ Math.Round(CW, 2)*/, "", "");

            //WF,WTA
            fun.dimrot1(dxf, v21, v2, -90, offset+OAL/6, 0.5, height, arrowsize, exline, "WF,WTA" /*+ Math.Round(CW, 2)*/, "", "");

            //LF,LTA
            fun.dimrot1(dxf, v26, v21, 180, offset+Math.Abs(v26.Y-v21.Y)/2, 0.5, height, arrowsize, exline, "LF,LTA" /*+ Math.Round(CW, 2)*/, "", "");

            //OAL,LPR
            fun.dimrot1(dxf, v26, v17, 180, offset*2 + OAW / 2+v17.Y, 0.5, height, arrowsize, exline, "OAL,LPR" /*+ Math.Round(CW, 2)*/, "", "");

            //OAW
            fun.dimrot1(dxf, new Vector2(v69_1.X, v69_1.Y + OAW / 2.0), new Vector2(v69_1.X, v69_1.Y - OAW / 2.0), -90, offset*2 +Math.Abs(v91.X-v69_1.X)+ OAW / 2, 0.5, height, arrowsize, exline, "OAW" /*+ Math.Round(CW, 2)*/, "", "");

            //WF,WTA(第二部分)
            fun.dimrot1(dxf, v91, v69_1, -102, offset + OAW / 2, 0.5, height, arrowsize, exline, "WF,WTA" /*+ Math.Round(CW, 2)*/, "", "");

            //PDPT
            fun.dimrot1(dxf, v83, v99, -66, offset, 0.5, height, arrowsize, exline, "PDPT" /*+ Math.Round(CW, 2)*/, "", "");

            //坐标系--------------------------------------------------------------------
            fun.Axis(dxf, v5, 180, 270, "", "", "", 1, height, 0);
            Line line1 = new Line(v5, fun.Polar(v5, -135 * pi / 180, LF));
            dxf.AddEntity(line1);
            String string1 = "MCS,PCS";
            Vector2 dian1 = new Vector2(fun.Polar(v5, -135 * pi / 180, LF).X - string1.Length * height, fun.Polar(v5, -135 * pi / 180, LF).Y);
            Text text1 = new Text("MCS,PCS", dian1, height, 0);
            dxf.AddEntity(text1);

            fun.Axis(dxf, new Vector2(v52.X - OAL, v52.Y), 180, 270, "Z", "X", "Y", 1, height, 0);

            fun.Axis(dxf, v69_1, 0, 270, "", "", "", 1, height, 0);
            Line line2 = new Line(v69_1, fun.Polar(v69_1, -135 * pi / 180, OAW / 2.0));
            dxf.AddEntity(line2);

            String string5 = "MCS,PCS";
            Vector2 dian2 = new Vector2(fun.Polar(v69_1, -135 * pi / 180, OAW / 2.0).X - string5.Length * height, fun.Polar(v69_1, -135 * pi / 180, OAW / 2.0).Y);
            Text text2 = new Text("MCS,PCS", dian2, height, 0);
            dxf.AddEntity(text2);

            //箭头---------------------------------------------------------------------------
            String string2 = "REL";
            fun.jt1(dxf, v22, -170, OAL, string2.Length * height, "REL", height);

            String string3 = "CRP";
            fun.jt1(dxf, v21, -160, OAL * 2, string2.Length * height, "CRP", height);

            String string4 = "PER";
            fun.jt1(dxf, v21, -45, LF, string2.Length * height, "PER", height);

            //角度标注
            fun.jdbz2(dxf, new Line(v88, fun.Polar(v88, 40 * pi / 180, 0.1)), new Line(v87, fun.Polar(v87, 60 * pi / 180, 0.1)), offset*2, height, arrowsize, exline, "AN", "", "");

            fun.jdbz2(dxf, new Line(v89, fun.Polar(v89, -50 * pi / 180, 0.1)), new Line(v87, fun.Polar(v87, -30 * pi / 180, 0.1)), offset * 2, height, arrowsize, exline, "GAMP", "", "");


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            
            fun.SetLayer(dxf);
            fun.SetByLayer(dxf);

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
